package dao;

import util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;
//create table book(
//        id int,
//        name varchar(20),
//        author varchar(20),
//        kind varchar(20),
//        price int
//        );

public class BookDao {

    public static void main(String[] args) throws SQLException {
        testInsert();
    }

    private static void testInsert() throws SQLException {
        Connection connection = DBUtil.getConnection();
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入书的id:");
        int id = scanner.nextInt();
        System.out.println("输入书的名字：");
        String name = scanner.next();
        System.out.println("输入书的作者：");
        String author = scanner.next();
        System.out.println("输入书的种类");
        String kind = scanner.next();
        System.out.println("输入书的价格：");
        int price = scanner.nextInt();

        String sql = "insert into book values (?,?,?,?,?) ";

        PreparedStatement statement = connection.prepareStatement(sql);

        statement.setInt(1, id);
        statement.setString(2, name);
        statement.setString(3, author);
        statement.setString(4, kind);
        statement.setInt(5, price);

        System.out.println("sql: " + statement);

        int ret = statement.executeUpdate();
        System.out.println("ret = " + ret);

        connection.close();
    }
}
